<%@ page contentType="text/html; charset=gbk" language="java" %>
<%request.setCharacterEncoding("gbk");%>
<%@include file="Conn.jsp"%>
<%@include file="MyJsp.jsp"%>
<%
	out.clear();
	MyJsp jsp=new MyJsp(request,response,out,session);
	Conn sqlca=null;

	java.sql.Statement stm=null;
	try{
	if(myjsp.r("datasource").equals(""))
	sqlca=new Conn();
	else
	sqlca=new Conn(myjsp.r("datasource"));
	stm=sqlca.createStatement();
	if(jsp.r("method").equals("query"))
	{
		try{
		//String sql=java.net.URLDecoder.decode(jsp.r("sql"),"gbk");
		//java.sql.ResultSet rs=stm.executeQuery(jsp.r("sql"));
		java.sql.ResultSet rs=stm.executeQuery(jsp.r("sql"));
		System.out.println("aaaa===================="+jsp.r("sql"));
		int col_count=rs.getMetaData().getColumnCount();
		String str1="";
		int rowid=0;
		for(int i=1;i<=col_count;i++)
		{
			if(i!=1) jsp.w("\t");
			jsp.w(rs.getMetaData().getColumnName(i));
		}//for
	while(rs.next())
	{
		jsp.w("\r\n");
		rowid++;
		for(int i=1;i<=col_count;i++)
		{
		if(i!=1) jsp.w("\t");
		str1=rs.getString(i);
		if(str1!=null)
		{
		str1=str1.replaceAll("\\\\","\\\\\\\\");
		str1=str1.replaceAll("\"","\\\\\"");
		str1=str1.replaceAll("\t","\\\\\t");
		str1=str1.replaceAll("\r\n","\\\\r\\\\n");
		str1=str1.replaceAll("\n","\\\\n");
		jsp.w(str1);
		}

		}

	}
		}catch(Exception e)
		{
		out.clear();
		jsp.w("false\t"+e.toString());
		}

	}
	if(jsp.r("method").equals("execute"))
	{
		try
		{
		stm.execute(jsp.r("sql"));
		//System.out.println(jsp.r("sql"));
		jsp.w("true\t");
		}catch(Exception e)
		{
			jsp.w("false\t"+e.toString());
		}
	}
	sqlca.commit();
	}catch(Exception e)
	{
	out.write(e.toString());

	}
	finally{
	if(stm!=null) stm.close();
	if(sqlca!=null)
	sqlca.close();
	}
%>
